#include "pagemaintbattery.h"
#include "ui_pagemaintbattery.h"

PageMaintBattery::PageMaintBattery(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageMaintBattery)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    initPages();
}

PageMaintBattery::~PageMaintBattery()
{
    delete ui;
}

void PageMaintBattery::initPages()
{
    for (int i=0;i<2 ;i++ ) {
        widget[i] = new QWidget(this);
        widget[i]->setGeometry(60,100,1150,620);
        widget[i]->setVisible(i==0);
    }
    //---------------------------------page1---------------------------------------------
    QLabel *FrameC31 = new QLabel(widget[0]);
    FrameC31->setGeometry(169,20,450,600);
    FrameC31->setStyleSheet("border: 1px solid white;");
    QLabel *FrameC32 = new QLabel(widget[0]);
    FrameC32->setGeometry(169+449,20,450,600);
    FrameC32->setStyleSheet("border: 1px solid white;");

    QLabel *labelSignalVolt = new QLabel(widget[0]);
    labelSignalVolt->setGeometry(20,20,150,600);
    labelSignalVolt->setText("单体电压(V)");
    labelSignalVolt->setStyleSheet("border: 1px solid white; font-size: 15pt; font-family: arial;color:white;");
    labelSignalVolt->setAlignment(Qt::AlignCenter);

    for(int i=0;i<2;i++)
    {
        for(int j=0;j<42;j++)
        {
            QLabel *bat_core_volt = new QLabel(widget[0]);
            bat_core_volt->setGeometry(180+88*(j%5)+i*(450),45+60*(j/5),78,40);
            bat_core_volt->setStyleSheet("border: 1px solid white; font-size: 15pt; font-family: arial;color:white;");
            bat_core_volt->setAlignment(Qt::AlignCenter);
            BatCoreVolt[i].append(bat_core_volt);

            QLabel *bat_core_volt_num = new QLabel(widget[0]);
            bat_core_volt_num->setGeometry(180+88*(j%5)+i*(450),85+60*(j/5),78,20);
            bat_core_volt_num->setStyleSheet("font-size: 10pt; font-family: arial;color:white;");
            bat_core_volt_num->setAlignment(Qt::AlignCenter);
            bat_core_volt_num->setText(QString().setNum(j+1));
            LabelBatVoltNum[i].append(bat_core_volt_num);
        }
    }
    //---------------------------------page2---------------------------------------------
    QLabel *FrameC51 = new QLabel(widget[1]);
    FrameC51->setGeometry(169,20,450,600);
    FrameC51->setStyleSheet("border: 1px solid white;");
    QLabel *FrameC52 = new QLabel(widget[1]);
    FrameC52->setGeometry(169+449,20,450,600);
    FrameC52->setStyleSheet("border: 1px solid white;");

    QLabel *labelSignalTemp = new QLabel(widget[1]);
    labelSignalTemp->setGeometry(20,20,150,600);
    labelSignalTemp->setText("温度(℃)");
    labelSignalTemp->setStyleSheet("border: 1px solid white; font-size: 15pt; font-family: arial;color:white;");
    labelSignalTemp->setAlignment(Qt::AlignCenter);
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<12;j++)
        {
            QLabel *bat_core_temp = new QLabel(widget[1]);
            bat_core_temp->setGeometry(180+88*(j%5)+i*(450),45+60*(j/5),78,40);
            bat_core_temp->setStyleSheet("border: 1px solid white; font-size: 15pt; font-family: arial;color:white;");
            bat_core_temp->setAlignment(Qt::AlignCenter);
            BatCoreTemp[i].append(bat_core_temp);

            QLabel *bat_core_temp_num = new QLabel(widget[1]);
            bat_core_temp_num->setGeometry(180+88*(j%5)+i*(450),85+60*(j/5),78,20);
            bat_core_temp_num->setStyleSheet("font-size: 10pt; font-family: arial;color:white;");
            bat_core_temp_num->setAlignment(Qt::AlignCenter);
            bat_core_temp_num->setText(QString().setNum(j+1));
            LabelBatTempNum[i].append(bat_core_temp_num);
        }
    }
}

void PageMaintBattery::on_Btn_Return_clicked()
{
    emit returnToMaintMenu();
}

void PageMaintBattery::on_Btn_Next_clicked()
{
    widget[0]->hide();
    widget[1]->show();
}

void PageMaintBattery::on_Btn_Pre_clicked()
{
    widget[1]->hide();
    widget[0]->show();
}

void PageMaintBattery::setBatCoreVolt(uint8_t car, uint8_t index, uint16_t volt)
{
    if(car > 1 || index >= BatCoreVolt[car].length())
        return;
    BatCoreVolt[car][index]->setText(QString("%1").arg(volt*0.001));
}

void PageMaintBattery::setBatCoreTemp(uint8_t car, uint8_t index,uint16_t temp)
{
    if(car > 1 || index >= BatCoreTemp[car].length())
        return;
    BatCoreTemp[car][index]->setText(QString("%1").arg((temp-550)*0.1));
}
